package com.ruoyi.address.service.impl;

import java.util.List;

import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.address.mapper.SysUserAddressMapper;
import com.ruoyi.address.domain.SysUserAddress;
import com.ruoyi.address.service.ISysUserAddressService;

/**
 * 用户地址Service业务层处理
 * 
 * @author ruoyi
 * @date 2025-02-19
 */
@Service
public class SysUserAddressServiceImpl implements ISysUserAddressService 
{
    @Autowired
    private SysUserAddressMapper sysUserAddressMapper;

    /**
     * 查询用户地址
     * 
     * @param addressId 用户地址主键
     * @return 用户地址
     */
    @Override
    public SysUserAddress selectSysUserAddressByAddressId(Long addressId)
    {
        return sysUserAddressMapper.selectSysUserAddressByAddressId(addressId);
    }

    /**
     * 查询用户地址列表
     * 
     * @param sysUserAddress 用户地址
     * @return 用户地址
     */
    @Override
    public List<SysUserAddress> selectSysUserAddressList(SysUserAddress sysUserAddress)
    {
        return sysUserAddressMapper.selectSysUserAddressList(sysUserAddress);
    }

    /**
     * 新增用户地址
     * 
     * @param sysUserAddress 用户地址
     * @return 结果
     */
    @Override
    public int insertSysUserAddress(SysUserAddress sysUserAddress)
    {
        return sysUserAddressMapper.insertSysUserAddress(sysUserAddress);
    }

    /**
     * 修改用户地址
     * 
     * @param sysUserAddress 用户地址
     * @return 结果
     */
    @Override
    public int updateSysUserAddress(SysUserAddress sysUserAddress)
    {
        return sysUserAddressMapper.updateSysUserAddress(sysUserAddress);
    }

    /**
     * 批量删除用户地址
     * 
     * @param addressIds 需要删除的用户地址主键
     * @return 结果
     */
    @Override
    public int deleteSysUserAddressByAddressIds(Long[] addressIds)
    {
        return sysUserAddressMapper.deleteSysUserAddressByAddressIds(addressIds);
    }

    /**
     * 删除用户地址信息
     * 
     * @param addressId 用户地址主键
     * @return 结果
     */
    @Override
    public int deleteSysUserAddressByAddressId(Long addressId)
    {
        return sysUserAddressMapper.deleteSysUserAddressByAddressId(addressId);
    }

    /**
     * 查询当前登录账户的地址信息
     *
     * */
    public List<SysUserAddress> selectSysUserAddressByCurrentUser(){
        // 获取当前登录用户的ID
        Long userId = SecurityUtils.getUserId();
        // 调用Mapper方法查询地址列表
        return sysUserAddressMapper.selectSysUserAddressByUserId(userId);
    }
}
